package com.studentmanagement.controller;

import com.our.learning.infrastructure.pojo.Response;
import com.studentmanagement.dto.StudentDTO;
import com.studentmanagement.service.StudentService;
import org.springframework.web.bind.annotation.*;

/**
 * 接受和处理有关学生的请求
 *
 * @author hexujie
 * @date 2023-06-20 23:10
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    private final StudentService studentService;

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    /**
     * 获取学生列表
     * stuId==null：                查询对应学生，
     * stuId==null&&classId==null： 查询所有学生的数据，
     * classId!=null&&stuId==null： 查询对应班级的全部学生
     */
    @GetMapping("/list")
    public Response studentList(Integer stuId, Integer classId) {
        return studentService.studentList(stuId, classId);
    }

    /**
     * 修改学生信息
     */
    @PatchMapping("/modify")
    public Response modifyStudent(@RequestBody StudentDTO studentDTO) {
        return studentService.modifyStudent(studentDTO);
    }

    /**
     * 获取学生学习情况
     */
    @GetMapping("/learningSituation/{stuId}")
    public Response getLearningSituation(@PathVariable Integer stuId) {
        return studentService.getLearningSituation(stuId);
    }

    /**
     * 添加学生到系统
     */
    @PostMapping
    public Response createStudent(@RequestBody StudentDTO studentDTO) {
        return studentService.createStudent(studentDTO);
    }

    /**
     * 从系统中删除学生
     */
    @DeleteMapping
    public Response deleteStudent(Integer id) {
        return studentService.deleteStudent(id);
    }
}
